package com.peas.platform.common.core.configuration;

import com.alibaba.cloud.nacos.ConditionalOnNacosDiscoveryEnabled;
import com.alibaba.cloud.nacos.NacosDiscoveryProperties;
import com.alibaba.cloud.nacos.NacosServiceManager;
import com.alibaba.cloud.nacos.discovery.NacosWatch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@ConditionalOnNacosDiscoveryEnabled
@Slf4j
public class NacosConfig {

    @Resource
    private NacosServiceManager nacosServiceManager;
    @Resource
    private NacosDiscoveryProperties nacosDiscoveryProperties;

    @Bean
    @ConditionalOnMissingBean
    public NacosWatch nacosWatch() {
        nacosDiscoveryProperties.setEphemeral(true);
        nacosDiscoveryProperties.getMetadata().put("platform", "java");
        return new NacosWatch(nacosServiceManager, nacosDiscoveryProperties);
    }

}
